package customerServlet;

import javaBean.customerDTO;
import javaBean.departmentDTO;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class showCustomer{
    public List showCustomer() {
        List<customerDTO> list = new ArrayList<customerDTO>();

        java.sql.Connection conn = null;
        java.sql.Statement sqlStmt = null;
        ResultSet rs = null;
        try {
            Class.forName("org.h2.Driver");
            conn = java.sql.DriverManager.getConnection("jdbc:h2:~/jpa-demo-db;MODE=MYSQL;DB_CLOSE_DELAY=-1", "sa", "sa");
            sqlStmt = conn.createStatement();
            rs = sqlStmt.executeQuery("select * from customer");//选择import java.sql.ResultSet

            while (rs.next()) {
                customerDTO customerdto= new customerDTO();
                customerdto.setId(rs.getString(1));
                customerdto.setName(rs.getString(2));
                customerdto.setPhone(rs.getString(3));
                customerdto.setPassword(rs.getString(4));
                list.add(customerdto);
            }
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
        return list;
    }
}
